package com.leyou.search.web;

import com.leyou.search.dto.SearchParamDTO;
import com.leyou.search.entity.Goods;
import com.leyou.search.service.SearchService;
import com.leyou.starter.elastic.entity.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import java.util.List;
import java.util.Map;

/**
 * @author ShenMin
 * @date 2021/7/21 17:15
 * @description
 */
@RestController
@RequestMapping("/goods")
public class SearchController {

    @Autowired
    SearchService searchService;

    @GetMapping("/suggestion")
    public Mono<List<String>> suggest(@RequestParam("key") String key) {
        return searchService.suggest(key);
    }

    @PostMapping("/list")
    public Mono<PageInfo<Goods>> pageQuery(@RequestBody SearchParamDTO searchParamDTO){
        return searchService.pageQuery(searchParamDTO);
    }

    @PostMapping("/filter")
    public Mono<Map<String,List<? extends Object>>> filterQuery(@RequestBody SearchParamDTO searchParamDTO){
        return searchService.filterQuery(searchParamDTO);
    }
}
